package cn.net.xyan.easy.spring.core.utils;

import cn.net.xyan.easy.spring.core.exception.StatusAndMessageError;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

/**
 * Created by xiashenpin on 16/1/17.
 */
public class JavaClassDeserializer extends JsonDeserializer<Class> {
    @Override
    public Class deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {

        try {
            String className = p.readValueAs(String.class);
            return Class.forName(className);
        } catch (ClassNotFoundException e) {
            throw new StatusAndMessageError(-99,e);
        }
    }
}
